package com.itheima.mm.mapper;

import com.itheima.mm.pojo.ReviewLog;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface ReviewLogMapper {


    /**
     * 添加审核记录
     * @param reviewLog
     */
    @Insert("INSERT INTO t_review_log(comments, status, question_id, user_id, create_date)\n" +
            "        VALUES (#{comments}, #{status}, #{questionId}, #{userId}, #{createDate})")
    void insert(ReviewLog reviewLog);


    /**
     * 根据题目id查询审核记录情况
     * @param questionId
     * @return
     */
    @Select("select id,comments,status," +
            "(select username from t_user where id=t_review_log.user_id) reviewer" +
            " from t_review_log " +
            "where question_id = #{questionId} " +
            "order by create_date desc limit 1")
    ReviewLog getByQuestionId(Integer questionId);
}